package com.wyt.controller;

import com.wyt.dao.mapper.AbilitiesMapper;
import com.wyt.dao.mapper.LikesMapper;
import com.wyt.dao.mapper.ServicesMapper;
import com.wyt.pojo.*;
import com.wyt.service.ClickLikeService;
import com.wyt.service.ResContent;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@Api(tags = "服务推荐接口")
@RequestMapping("/introduce")
public class ServiceIntroduceController {

    @Autowired
    private ResContent resContent;

    @Autowired
    private ClickLikeService clickLikeService;


    @GetMapping("/content")
    public List<ResServicesVO> resContent(){

        return resContent.findComment();
    }

    @PostMapping("/likes")
    public ResLikeVO ClickLikes(@RequestBody ReqLikeVO reqLikeVO){
        return clickLikeService.ClickLike(reqLikeVO.getUserId(),reqLikeVO.getAbilityId());
    }
    // 开发使用，访问该接口初始化数据库，将全部用户全部能力点赞状态初始化
//    @GetMapping("/init")
//    public void initLikes(){
//        List<Services> allServices = servicesMapper.findAllServices();
//        ArrayList<Abilities> allAbilities = new ArrayList<>();
//        // 找到所有服务的所有能力
//        for(Services s:allServices){
//            int sid = s.getServiceId();
//            allAbilities.addAll(abilitiesMapper.queryAbilitiesList(sid));
//        }
//        // 为所有用户的所有能力点赞状态初始化
//        for(Abilities a:allAbilities){
//            for(int i=1;i<=15;i++)
//            {
//                // 生成随机数0 or 1
//                int rd=Math.random()>0.5?0:1;
//                likesMapper.initLikes(i,a.getAbilityId(),rd);
//            }
//        }
//    }






}
